namespace BM.Tools.WebControls.MForm.Navigation.XPath
{
    using System.Collections.ObjectModel;

    /// <summary>
    /// The definition of the compound location step. 
    /// The compund location step consists of several location steps separated by the'|' sign.
    /// </summary>
    public class CompoundLocationStep : LocationStep
    {
        private Collection<LocationStep> compoundElements = new Collection<LocationStep>();

        /// <summary>
        /// Gets CompoundElements.
        /// </summary>
        /// <value>
        /// The compound elements.
        /// </value>
        public Collection<LocationStep> CompoundElements
        {
            get
            {
                return compoundElements;
            }
        }

        /// <summary>
        /// Creates the location step out of its string definition
        /// </summary>
        /// <param name="locationStepText">
        /// The locationStep text.
        /// </param>
        /// <returns>
        /// the <see cref="CompoundLocationStep" /> object
        /// </returns>
        public static new CompoundLocationStep Create(string locationStepText)
        {
            string[] parts = locationStepText.Split('|');
            var compoundLocationStep = new CompoundLocationStep();
            foreach (string s in parts)
            {
                compoundLocationStep.CompoundElements.Add(LocationStep.Create(s));
            }

            return compoundLocationStep;
        }
    }
}